<?php
namespace app\common\service;
use \app\common\model\LitestoreOrder as LitestoreOrderModel;
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/3/8
 * Time: 15:33
 */
class LitestoreOrder extends Base {
    public function __construct()
    {
       $LitestoreOrderModel = new LitestoreOrderModel();
       $this->model = $LitestoreOrderModel;
    }

    /**
     *  商家订单中心
     */
    public function StoreOrderByList($uid,$limit,$where){
        $map['user_id'] = $uid;
        if($where){
            $map['pay_status'] = $where;
        }
        $order = 'id desc';
        $LitestoreOrderModel = LitestoreOrderModel::where($map)->order($order)->group('id')->field('id,user_id,pay_price,pay_status,createtime')->limit($limit);
        $data =  collection($LitestoreOrderModel->with("orderLists")->select())->toArray();
        $LitestoreShopComment = new LitestoreShopComment();
        //待评价
        foreach($data as &$v){
            foreach($v["order_lists"] as &$vv){
                    $v['goods_name']=$vv['goods_name'];
                    $v['goods_id']=$vv['goods_id'];
                    $v['average'] =  $LitestoreShopComment->isComment($v['user_id'],$vv['goods_id']);
            }
            unset($v['order_lists']);
        }
       return  $data;

    }
}